package com.test;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

import com.entity.School;
import com.entity.Student;
import com.service.ISchoolService;
import com.service.IStudentService;
import com.service.impl.SchoolService;
import com.service.impl.StudentService;
import com.tools.MyTools;

public class Init {
	
	/**
	 * 初始化
	 */
	@Test
	public void save(){
		Set<String> set=new HashSet<>();
		for(int i=1000;i<1100;i++){
			//新建一个学校
			School school=new School();
			school.setName(MyTools.getSchoolName());
			school.setInfo(school.getName()+"是一所有着悠久历史的名校");
			school.setId(MyTools.getId(20));
			ISchoolService schoolService=new SchoolService();
			
			if(set.add(school.getName())){
				boolean add = schoolService.add(school);
				if(add){
					for(int j=1;j<(int)(Math.random()*200+100);j++){
						Student student=new Student();
						student.setId(MyTools.getId(20));
						student.setName(MyTools.getName(j%2+1));
						student.setAge(j%80+20);
						student.setResult(j%100);
						student.setSchool(school);
						IStudentService service=new StudentService();
						service.add(student);
					}	
				}
				
			}
			
		}
	}
}
